package net.seehope.foodie.service.task;

import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

@Service
public class AsyncTask {
	
	private static final Logger log = LoggerFactory.getLogger(AsyncTask.class);
	

	@Async
	public Future<Boolean> asyncTask1() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(1000);
		long end = System.currentTimeMillis();
		log.info("task 1 cost"+(end-start)+"millsecs");
		return new AsyncResult<Boolean>(true);
		
		
	}
	
	@Async
	public Future<Boolean> asyncTask2() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(1000);
		long end = System.currentTimeMillis();
		log.info("task 2 cost"+(end-start)+"millsecs");
		return new AsyncResult<Boolean>(true);
		
		
	}
	
	@Async
	public Future<Boolean> asyncTask3() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(1000);
		long end = System.currentTimeMillis();
		log.info("task 3 cost"+(end-start)+"millsecs");
		return new AsyncResult<Boolean>(true);
		
		
	}
	
	
}
